<template>
  <div class="home-container">
   
    <tab-bar></tab-bar>
        <van-popup v-model="show" position="left" :style="{ height: '100%',width:'85%' }" >
            <popup></popup>
        </van-popup>

      <div class="content">
           <div class="header">
          <div class="left" @click="openUserInfo">
              <van-icon size="22" name="user-circle-o" />
          </div>
          <div class="search">
              <van-search shape="round" v-model="searchContent"  input-align="left" placeholder="请输入搜索关键词" />
          </div>
          <div class="right">
              <van-icon size="22" name="apps-o" />
          </div>
      </div>

      <!-- swiper -->
      <div class="swiper-content">
          <div class="swiper-item">
              <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
                <van-swipe-item  v-for="(item,index) in bannerList" :key="index">
                    <img :src="item.pic" alt="item.typeTitle">
                </van-swipe-item>
              </van-swipe>
          </div>
      </div>

     <!-- // 每日推荐 -->

     <div class="ball-content"> 
        <div class="ball-item" v-for="(ball,index) in ballList" :key="index">
            <div class="icon"><img :src="ball.iconUrl" alt=""></div>
            <span>{{ ball.name }}</span>
        </div>
     </div>

     <!-- 推荐歌单 -->

     <div class="recommend-content">
         <div class="recommend-head">
             <div class="title">推荐歌单</div>
             <div class="more">
                 <p>更多</p>
                 <van-icon size="10" name="arrow" />
             </div>
         </div>

         <div class="recommend-wrapper">
             <div class="recommend-item" v-for="(recommend,index) in recommendList" :key="index">
                 <div class="pic">
                     <img :src="recommend.picUrl" alt="">
                     <div class="play-count">
                     <van-icon size="8" color="#ffffff" name="play-circle-o" />
                     <span>{{ (recommend.playCount / 10000).toFixed(0) }}万</span>
                     </div>
                 </div>
                 <span>{{recommend.name}}</span>
             </div>
         </div>
     </div>

 <!-- 精选音乐视频 -->
     <div class="recommend-content">
         <div class="recommend-head">
             <div class="title">精选推荐歌单</div>
             <div class="more">
                 <p>更多</p>
                 <van-icon size="10" name="arrow" />
             </div>
         </div>

         <div class="recommend-wrapper">
             <div class="recommend-item" v-for="(recommendVedio,index) in recommendVieoList" :key="index">
                 <div class="pic">
                     <img :src="recommendVedio.cover" alt="">
                     <div class="play-count">
                     <van-icon size="8" color="#ffffff" name="play-circle-o" />
                     <span>{{ (recommendVedio.playCount / 10000).toFixed(0) }}万</span>
                     </div>
                 </div>
                 <span>{{recommendVedio.name}}</span>
             </div>
         </div>
     </div>

     <!-- 推荐mv -->

     <!-- 精选音乐视频 -->
     <div class="recommend-content">
         <div class="recommend-head">
             <div class="title">推荐MV</div>
             <div class="more">
                 <p>更多</p>
                 <van-icon size="10" name="arrow" />
             </div>
         </div>

         <div class="recommend-wrapper">
             <div class="recommend-item" v-for="(recommendMv,index) in recommendMvList" :key="index">
                 <div class="pic">
                     <img :src="recommendMv.cover" alt="">
                     <div class="play-count">
                     <van-icon size="8" color="#ffffff" name="play-circle-o" />
                     <span>{{ (recommendMv.playCount / 10000).toFixed(0) }}万</span>
                     </div>
                 </div>
                 <span>{{recommendMv.name}}</span>
             </div>
         </div>
     </div>


      <div>

      </div>
      </div>
     
    
  </div>
    
</template>


<script>
import {getHomeBanner,getHomeBallList,getRecommendList,getRecommendVedio,getRecommendMv,defultSearch}  from '../api/home/home'
import TabBar from '../components/tabbar/tabBar.vue'
// import Popup from '@/components/tabbar/tabBar/Popup.vue'
import Popup from '../components/tabbar/Popup.vue'
export default {
    name:'Home',
    components:{
        TabBar,
        Popup,
    },
    data(){
        return{
            HomeData:{},
            searchContent:'',
            bannerList:[],
            ballList:[],
            recommendList:[],
            recommendVieoList:[],
            recommendMvList:[],
            show:false  

        }
    },
    mounted(){
        this.getHomeData()
        this.getHomeBall()
        this.getHomeRecommend()
        this.getHomeRecommendVedio()
        this.getHomeRecommendMv()
        this.getDefultSearch()
    },
    methods:{
        async getHomeData(){
            const res = await getHomeBanner()
            if(res && res.status === 200){
                this.bannerList = res.data.banners
            }
            console.log(res)
        },

        async getHomeBall(){
            const ballRes = await getHomeBallList()
            console.log(ballRes)
            if(ballRes && ballRes.status === 200){
                this.ballList = ballRes.data.data
                console.log(this.bannerList)
            }
        },

        async getHomeRecommend(){
            const recommend = await getRecommendList()
            if(recommend && recommend.status === 200){
                this.recommendList = recommend.data.result
                console.log(this.recommendList)
            }
            // console.log(recommend)
        },

        // 获取推荐视频

        async getHomeRecommendVedio(){
            const recommendVedio = await getRecommendVedio()
            if(recommendVedio && recommendVedio.status === 200){
                this.recommendVieoList = recommendVedio.data.data
            }
            console.log(recommendVedio)
        },

        // 获取推荐mv

        async getHomeRecommendMv(){
            const recommendMv = await getRecommendMv()
            if(recommendMv && recommendMv.status === 200){
                // this.recommendMvList = recommendMv.data.result
                console.log(recommendMv)
                this.recommendMvList = recommendMv.data.data
            }
        },

        // 获取默认搜索

        async getDefultSearch(){
            const defultS = await defultSearch()
            
            console.log(defultS)
        },
        openUserInfo(){
            this.show = true
        }
    }
    
}
</script>

<style scoped>
.home-container{
    height: 100%;
    width: 100%;
}
.content{
    /* width: 100%; */
    padding:10px;
    /* height: 100%; */
    /* background-color: #eeeeee; */
    padding-bottom: 20%;

}
.header{
    display: flex;
    /* padding:10px; */
    justify-content: space-between;
    align-content: center;
    position: fixed;
    width: 100%;
    height: 50px; 
    line-height: 50px;
    top: 0;
    z-index: 1;
    background-color: #fff;
}
.left{
    width: 15%;
    /* background-color: red; */
    padding: 5px;
    /* text-align: center; */
}
.right{
    width: 15%;
    /* background-color: green; */
    padding: 5px;
    text-align: center;
    /* text-align: center; */
}
.search{
    flex: 1;
    text-align: center;
    line-height: 50px;
    display: flex;
    align-items: center;

}
.van-search{
    padding: 0;
}

.swiper-content{
    width: 100%;
    height: 150px;
    margin-top: 50px;
    /* margin-top:50px; */
    /* padding:10px; */


}
.swiper-item{
    height: 100%;
    width: 100%;
    /* border-radius: 5px; */
}
 .my-swipe {
    border-radius: 7px;

 }
.van-swipe-item  img{
      height: 100%;
      width: 100%;
  }


.ball-content{
      margin-top: 5px;
      display: flex;
      overflow: auto;
      border-bottom: 1px solid #eeeeee;
      padding-bottom: 10px;

}
.ball-content::-webkit-scrollbar { display: none }
.ball-item{
    height: 100%;
    display: flex;
    width: 50px;
    flex-direction: column;
    justify-content: center;
    align-content: center;
}
.ball-item:nth-child(n+2){
    margin-left: 20px;
}
.icon{
    height: 100%;
    width: 50px;
}
.ball-item img{
    height: 100%;
    width: 100%;
    background-color: red;
    border-radius: 50%;
}
.ball-item span{
    text-align: center;
}
.recommend-content{
    height: 28%;
    margin-top: 10px;
    border-bottom: 8px solid #eeeeee;
    padding-bottom: 12px;
    
}
.recommend-content .recommend-head{
    display: flex;
    justify-content: space-between;
}
.recommend-content .recommend-head .title{
    font-size: 18px;
    font-weight: bold;
}
.recommend-content .recommend-head .more{
    text-align: center; 
    display: flex;
    align-content: center;
    justify-content: center;
    width: 50px;
    height: 30px;
    border: 1px solid #eeeeee;
    line-height: 30px;
    border-radius:30px ;
}
.more  .van-icon-arrow{
    line-height: 30px;
}
.recommend-wrapper{
    width: 100%;
    margin-top: 5px;
    overflow: auto;
    display: flex;
}
.recommend-wrapper::-webkit-scrollbar { display: none }
.recommend-item{
    position: relative;
    height: 100%;
    text-align: center;
    width: 32%;
    flex-shrink:0
}
.recommend-item:nth-child(n+2){
    margin-left: 10px;
}
.recommend-item .pic img{
    height: 100%;
    width: 100%;
    border-radius: 5px;
}
.play-count{
    position: absolute;
    top: 5px;
    right: 10%;
    display: flex;
    justify-content: center;
    align-content: center;
    color: #ffffff;
}
.play-count span{
    color: #ffffff;
}
.play-count .van-icon-play-circle-o{
    display: block;
    margin-top: 3px;
    margin-right: 2px;
}
</style>